home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / irsim / prints.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  2KB  |  94 lines

  1. /* 
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     ********************************************************************* 
  13.  */
  14.  
  15. /*
  16.  * Prints various messages but deals with varargs correctly.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <varargs.h>
  21. #include "defs.h"
  22.  
  23.  
  24. extern    FILE  *logfile;
  25.  
  26.  
  27. private void logprint( s )
  28.   register char  *s;
  29.   {
  30.     static int  docomment = 1;
  31.  
  32.     while( *s != '\0' )
  33.       {
  34.     if( docomment )
  35.       {
  36.         (void) putc( '|', logfile );
  37.         (void) putc( ' ', logfile );
  38.         docomment = 0;
  39.       }
  40.     (void) putc( *s, logfile );
  41.     if( *s++ == '\n' )
  42.         docomment = 1;
  43.       }
  44.   }
  45.  
  46.  
  47. /* VARARGS */
  48. public void lprintf( va_alist )
  49.   va_dcl
  50.   {
  51.     va_list  args;
  52.     char     *fmt;
  53.     FILE     *fp;
  54.     char     buff[ 300 ];
  55.  
  56.     va_start( args );
  57.     fp = va_arg( args, FILE * );
  58.     fmt = va_arg( args, char * );
  59.     (void) vsprintf( buff, fmt, args );
  60.     va_end( args );
  61.  
  62.     (void) fputs( buff, fp );
  63.  
  64.     if( logfile != NULL )
  65.     logprint( buff );
  66.   }
  67.  
  68.  
  69. /* VARARGS */
  70. public void error( va_alist )
  71.   va_dcl
  72.   {
  73.     va_list  args;
  74.     char     *filename;
  75.     int      lineno;
  76.     char     *fmt;
  77.     char     buf1[ 100 ], buf2[ 200 ];
  78.  
  79.     va_start( args );
  80.     filename = va_arg( args, char * );
  81.     lineno = va_arg( args, int );
  82.     fmt = va_arg( args, char * );
  83.     (void) sprintf( buf1, "(%s,%d): ", filename, lineno );
  84.     (void) vsprintf( buf2, fmt, args );
  85.     va_end( args );
  86.     (void) fputs( buf1, stderr );
  87.     (void) fputs( buf2, stderr );
  88.     if( logfile != NULL )
  89.       {
  90.     logprint( buf1 );
  91.     logprint( buf2 );
  92.       }
  93.   }
  94.